#This file creates counts of executive, judicial, and legislative provisions included in each document
rm(list = ls())
points <- read.csv("roll_call_matrix.csv")
groups <- read.csv("groups_by_vote_type.csv")
names <- subset(read.csv("all_colonies_1d_ideal_points.csv"), select = "name")

executive <- groups$name[groups$group == 3]
leg <- groups$name[groups$group == 4]
judicial <- groups$name[groups$group == 5]
rights <- groups$name[groups$group == 12]
all <- groups$name[groups$group %in% 1:13]

points$num.exec <- rowSums(points[,names(points) %in% executive])
points$num.leg <- rowSums(points[,names(points) %in% leg])
points$num.jud <- rowSums(points[,names(points) %in% judicial])
points$num.rights <- rowSums(points[,names(points) %in% rights])
points$num.prov <- rowSums(points[,names(points) %in% all])

data <- subset(points, select = c(num.exec, num.leg, num.jud, num.rights, num.prov))
data$Constitution.Name <- names$name
data$Constitution.Name[data$Constitution.Name == "Charter: Delaware & Pennsylvania - 1701"] <- "Charter: DE & PA - 1701"
data$Constitution.Name[data$Constitution.Name == "Constitution of the United States of America"] <- "USA - 1788"
data$Constitution.Name[data$Constitution.Name == "Constitution of the United States of America + BOR"] <- "USA + BOR - 1791"
write.csv(data, "exec_leg_jud_count.csv")
